package mq

import (
	"fmt"
	"github.com/streadway/amqp"
	"time"
	"yunpan/cache/log"
	"yunpan/config"
)



func Publish(exchange, routingKey string, msg []byte) bool {
	if !initChannel(config.RabbitURL) {
		return false
	}

	err := channel.Publish(
		exchange,
		routingKey,
		false,
		false,
		amqp.Publishing{
			Headers:         nil,
			ContentType:     "text/plain",
			ContentEncoding: "",
			DeliveryMode:    0,
			Priority:        0,
			CorrelationId:   "",
			ReplyTo:         "",
			Expiration:      "",
			MessageId:       "",
			Timestamp:       time.Time{},
			Type:            "",
			UserId:          "",
			AppId:           "",
			Body:            msg,
		})

	if err != nil {
		log.Ob().Warn(err.Error())
		return false
	}
	fmt.Println("向队列发送了一条消息"+string(msg))
	return true
}